﻿@using Common.Property

@{
    Layout = "~/Views/Shared/_Edit.cshtml";
}
@model DTO.DTO.Sys.Module.ModuleDetailDTO
<form class="layui-form" action="" style="margin-top:20px;">
    <input type="hidden" name="Id" value="@Model.Id" />
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">所属父级</label>
            <div class="layui-input-inline">
                <select name="ParentId" lay-search="">
                    <option value="">根级别</option>
                    @foreach (Domain.Sys.Module item in ViewBag.ModuleList)
                    {
                        var depth = "";
                        for (var i = 0; i < item.Depth; i++)
                        {
                            depth += " - ";
                        }
                        if (item.Id == Model.ParentId)
                        {
                            <option value="@(item.Id)" selected="">@(depth + item.Name)</option>
                        }
                        else
                        {
                            <option value="@(item.Id)">@(depth + item.Name)</option>
                        }
                    }
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">模块名称</label>
        <div class="layui-input-inline">
            <input type="text" name="Name" lay-verify="required" autocomplete="off" placeholder="模块名称" class="layui-input" value="@Model.Name">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">模块类型</label>
        <div class="layui-input-inline">
            <select name="Type" lay-verify="Type">
                <option value="">请选择</option>
                @foreach (Common.Utility.SelectItem item in ViewBag.Types)
                {
                    if (item.Value == Model.Type)
                    {
                        <option value="@(item.Value)" selected="">@(item.Text)</option>
                    }
                    else
                    {
                        <option value="@(item.Value)">@(item.Text)</option>
                    }
                }
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">访问地址</label>
        <div class="layui-input-block">
            <input type="text" name="PageUrl" autocomplete="off" placeholder="访问地址" class="layui-input" value="@Model.PageUrl">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-inline">
            <input type="text" name="Sort" lay-verify="Sort|required" autocomplete="off" placeholder="排序" class="layui-input" value="@Model.Sort">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-inline">
            <input type="checkbox" @(Model.Status == E_Status.Enabled.ToString() ? "checked=''" : "") name="Status" lay-skin="switch" lay-filter="switchTest" lay-text="正常|禁用">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
@section script{
    <script>
        layui.use("form", function () {
            var form = layui.form
                , layer = layui.layer
                , $ = layui.$;

            var index = parent.layer.getFrameIndex(window.name);

            //监听提交
            form.on('submit(submit)', function (data) {
                var formData = data.field;
                formData.Status = formData.Status === "on" ? "@E_Status.Enabled.ToString()" : "@E_Status.Disable.ToString()";
                $.post("Save", formData, function (d) {
                    if (d.code === 0) {
                        layer.msg(d.msg, { icon: 1 });
                        setTimeout(function () {
                            parent.layer.close(index);
                        }, 1000);
                    }
                    else {
                        layer.msg(d.msg, { icon: 2 });
                    }
                })
                return false;
            });


            //自定义验证规则
            form.verify({
                Sort: [/^\d+$/, '排序必须是包含0的正整数！']
            });
        });
    </script>
}

